import 'package:sow_app_core/sow_app_core.dart';
import 'package:test/test.dart';

import 'package:sow_app_mock/sow_app_mock.dart';

void main() {
  group('info controller test group', () {
    final MockInfoPresenter presenter = MockInfoPresenter();
    final RestClient client = MockRestClient();
    final controller = MockInfoController(presenter, client);
    test("should present valid user nickName when invoke initUserNickName",
        () async {
      try {
        await controller.init();
        await Future.doWhile(() => presenter.flag = false);
      } catch (e) {
        expect(e, isA<ServerException>());
        expect(presenter.user.nickName, User.empty.nickName);
      }
    });
    test("should present valid user nickName when invoke initUserNickName",
        () async {
      client.setAuthorization('404');
      await controller.init();
      await Future.doWhile(() => presenter.flag = false);
      expect(presenter.user.nickName, User.empty.nickName);
    });
    test("should present valid user nickName when invoke initUserNickName",
        () async {
      client.setAuthorization('666');
      await controller.init();
      await Future.doWhile(() => presenter.flag = false);
      expect(presenter.user.nickName, isNot(User.empty.nickName));
    });
  });
}
